<template>
	<view class="container">
		<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="80">
			<u-form-item label="分配人员" prop="username" borderBottom @click="show = true" ref="item1">
				<u--input v-model="form.username" disabled disabledColor="#ffffff" placeholder="请选择"
					suffixIcon="arrow-down"></u--input>
			</u-form-item>
			<u-form-item label="客户名称" prop="nickname" borderBottom ref="item1">
				<u--input v-model="form.nickname" readonly></u--input>
			</u-form-item>
		</u--form>
		<u-button @click="submit" color="#19BC9C">提交</u-button>
		<u-picker :show="show" :columns="adminlist" keyName="username" @cancel="show = false"
			@confirm="confirm"></u-picker>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					username: '',
					name: '',
					adminid: 0,
					busid: 0
				},
				rules: {
					'username': {
						type: 'string',
						required: true,
						message: '请选择分配人员',
						trigger: ['blur', 'change']
					},
					'nickname': {
						type: 'string',
						required: true,
						message: '请填写客户名称',
						trigger: ['blur', 'change']
					},
				},
				adminlist: [],
				show: false,
				LoginUser: {},
			};
		},
		onLoad(options) {
			this.form.busid = options.busid ?? 0
			this.form.nickname = options.nickname ?? 0
		},
		onReady() {
			this.$u.auth.check()
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
			this.getAdminData()
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {
			confirm({
				value
			}) {
				this.show = false
				this.form.username = value[0].username
				this.form.adminid = value[0].id
			},
			async getAdminData() {
				let result = await this.$u.api.admin.adminlist()
				if (result.code == 1) {
					this.adminlist.push(result.data)
				}
			},
			submit() {
				this.$refs.uForm.validate().then(async () => {
					let result = await this.$u.api.business.HighseaOperate({
						busid: this.form.busid,
						adminid: this.form.adminid,
						status: 'allot'
					})
					if (result.code == 1) {
						this.$refs.uToast.show({
							type: 'success',
							message: result.msg,
							complete: () => {
								uni.navigateTo({
									url: '/pages/business/highsea/index'
								})
							}
						})
					} else {
						this.$refs.uToast.show({
							type: 'error',
							message: result.msg,
						})
					}
				}).catch(errors => {})
			}
		}
	};
</script>

<style>
	.container {
		height: 100%;
		margin: 0 20rpx;
		box-sizing: border-box;
	}
</style>